﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using UnityEngine.UI;
public class StartUI : UIBase
{
    public override void OnDisplay(object args)
    {
        base.OnDisplay(args);
        Get<Button>("Start").onClick.SetListener(() => {
            if (Data.Instance.CheckIfDataTypeExist(DataType.LevelItemsInfo) == true)
            {

                    UIManager.Instance.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
              ("注意", "确定要开始新的关卡吗?\n之前的进度将会被销毁", null, "确定", "取消", () => {
                  //     MessageManager.Instance.Get<GameControl.GameAction>().DispatchMessage(GameControl.GameAction.EndCurrentLevel, this, null);
                  Data.Instance.ClearDataTypeAndSave(DataType.LevelItemsInfo);
                  ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair("PPT", typeof(TeachProcedure)));
                  //   StartLevel(LevelManager.Instance.FirstLevel);
              }));
            }
            else
            {
                ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair("PPT", typeof(TeachProcedure)));
            }


        });
        Get<Button>("Continue").onClick.SetListener(() => {
            if (Data.Instance.CheckIfDataTypeExist(DataType.LevelItemsInfo) == true)
            {
                StartLevel(Data.Instance.Get<GameMap.ItemsData>(DataType.LevelItemsInfo).CurrentScene);
            }
            else
            {

                UIManager.Instance.Open("DialogWindowUI", 4, args: new DialogWindowUI.DialogWindowUIArg
      ("注意", "没有存档", null, "确定", () => { }));
            }



        });
        Get<Button>("Exit").onClick.SetListener(() => {
            #if UNITY_EDITOR
                        UnityEditor.EditorApplication.isPlaying = false;
            #else
                                Application.Quit();
            #endif
        });
    }
  void StartLevel(string name)
    {
        ProcedureManager.Instance.ChangeTo<SceneLoadProcedure>(new SceneLoadPair(name, typeof(GameProcedure)));
    }
    protected override void OnClose()
    {
        base.OnClose();

    }
    private void OnDestroy()
    {
     //   Debug.Log("!!");
    }
}
